package com.example.datacollection.api;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.util.ArrayList;
import java.util.List;

public class PopulationCommonMethod {
    public static void collection(List<WebElement> elementTwos, ArrayList<Object> listTwo, WebDriver driver) {
        for (WebElement elementTwo : elementTwos) {
            WebElement element = elementTwo.findElement(By.xpath(".//strong"));
            //针对隐藏标签的措施
            if (StringUtils.isEmpty(element.getText())) {
                String script = "return arguments[0].innerText";
                String hiddenText = (String) ((JavascriptExecutor) driver).executeScript(script, element);
                listTwo.add(hiddenText);
                continue;
            }
            listTwo.add(elementTwo.getText());
        }
    }

}
